<template>
  <div class="app-container">
       <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="title" placeholder="课程名称"/>
      </el-form-item>

      <el-form-item>
            <el-radio-group v-model="status">
                
                <el-radio :label="'Normarl'">已发布</el-radio>
                <el-radio :label="'Draft'">未发布</el-radio>
               
            </el-radio-group>
          
    
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getCoursesByCondition()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

   <el-table
      :data="list"
      border
      fit
      highlight-current-row>
      <el-table-column
        label="序号"
        width="120"
        align="center"
        >
        <template slot-scope="scope">
          {{ (current - 1) * pageSize + scope.$index + 1 }}
          <!-- {{scope.row.id}} -->
        </template>
      </el-table-column>

      <el-table-column prop="title" label="课程名称" />

      <el-table-column label="课程状态" width="280">
        <template slot-scope="scope">
          {{ scope.row.status==='Normal'?'已发布':'未发布' }}
        </template>
      </el-table-column>

      <el-table-column prop="lessonNum" width="120" label="课时数" />

      <el-table-column prop="gmtModified" label="添加时间" width="200"/>

      <el-table-column prop="viewCount" label="浏览数量" width="100" />

      <el-table-column label="操作" width="600" align="center">
        <template slot-scope="scope">
          <router-link :to="'/edu/course/info/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">编辑课程基本信息</el-button>
          </router-link>
          <router-link :to="'/edu/course/chapter/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">编辑课程大纲信息</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除课程信息</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="current"
      :page-size="pageSize"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getCoursesByCondition"
    />
  </div>

</template>

<script>
import course from "../../../api/edu/course";
export default {
    data(){
        return{
            list:[],//课程信息列表
            current:1, // 当前页
            pageSize:8,
            total:0,
            title:'',
            status:'',
        }
    },
    created(){
        this.getCoursesByCondition()
    },
    methods:{
        getCoursesByCondition(current=1){
            this.current = current
            course.getCoursesByCondition(this.current,this.pageSize,this.title,this.status).then(response=>{
            this.list = response.data.pageCourses.items
            this.total = response.data.pageCourses.total
        })
        },
        resetData(){
            this.title = '',
            this.status= '',
            this.getCoursesByCondition()
        },
        removeDataById(courseId){
            
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                    }).then(() => {
                    course.deleteCourse(courseId).then(res=>{

                        this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                        this.getCoursesByCondition()
                    })
                    
                    }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
                 })
            
        }
        
    }
}
</script>

<style>

</style>